package com.yuexunit.finance.system.action.v1.dto;

import com.yuexunit.core.ConfigPropertites;
import com.yuexunit.finance.context.FinanceConstant;
import com.yuexunit.finance.project.entity.FinanceMoneyStatementEntity;
import com.yuexunit.finance.project.entity.lexicon.OperatorRoleEnum;
import com.yuexunit.finance.project.entity.lexicon.StatementStateEnum;
import com.yuexunit.finance.system.entity.LendUnitInfoEntity;
import com.yuexunit.finance.system.entity.LoansMoneyInfoEntity;
import com.yuexunit.finance.system.entity.LoansMoneyRecordInfoEntity;
import com.yuexunit.finance.system.service.LendUnitInfoService;
import com.yuexunit.inject.ComponentFactory;
import com.yuexunit.util.DateUtil;

public class LonsMoneyInfoCastor {
	public static FinanceMoneyStatementEntity fromLoansMoenyInfo(LoansMoneyInfoEntity entity, LoansMoneyRecordInfoEntity record) {
		LendUnitInfoService lendUnitInfoService = ComponentFactory.loadClass(LendUnitInfoService.class);
		LendUnitInfoEntity lend = lendUnitInfoService.inquireLendUnitInfoDetail(entity.getLendUnitId());
		
		FinanceMoneyStatementEntity statement = new FinanceMoneyStatementEntity();
		if (null == record) {
			statement.setAmount(entity.getAmount());
			statement.setStatementDate(DateUtil.parseDateInt(entity.getCreateDateTime().toString()));
		} else {
			statement.setAmount(record.getAmount());
			statement.setStatementDate(DateUtil.parseDateInt(record.getOperateTime().toString()));
		}
		statement.setReceiptName(ConfigPropertites.getProperties("platform.name"));
		statement.setReceiptType(OperatorRoleEnum.PLATFORM.ordinal());
		statement.setReceiptTenantId(FinanceConstant.DEFAULT_PLATFORM_WEB_TENANT);
		statement.setDisbursementType(OperatorRoleEnum.OTHER.ordinal());
		statement.setDisbursementName(lend.getLendUnitName());
		statement.setDisbursementId(entity.getLendUnitId());
		statement.setStatementSource("LOANS_MONEY");
		statement.setStatementState(StatementStateEnum.PAID);
		statement.setStatementSourceId(entity.getLoansMoneyId());
		return statement;
	}
	
	public static FinanceMoneyStatementEntity fromReturnLoansMoenyInfo(LoansMoneyInfoEntity entity, LoansMoneyRecordInfoEntity record) {
		LendUnitInfoService lendUnitInfoService = ComponentFactory.loadClass(LendUnitInfoService.class);
		LendUnitInfoEntity lend = lendUnitInfoService.inquireLendUnitInfoDetail(entity.getLendUnitId());
		
		FinanceMoneyStatementEntity statement = new FinanceMoneyStatementEntity();
		statement.setAmount(record.getAmount());
		statement.setReceiptName(lend.getLendUnitName());
		statement.setReceiptType(OperatorRoleEnum.OTHER.ordinal());
		statement.setDisbursementName(ConfigPropertites.getProperties("platform.name"));
		statement.setDisbursementType(OperatorRoleEnum.PLATFORM.ordinal());
		statement.setDisbursementTenantId(FinanceConstant.DEFAULT_PLATFORM_WEB_TENANT);
		statement.setStatementSource("LOANS_MONEY_RETURN");
		statement.setStatementState(StatementStateEnum.PAID);
		statement.setStatementSourceId(entity.getLoansMoneyId());
		statement.setStatementDate(DateUtil.parseDateInt(record.getOperateTime().toString()));
		return statement;
	}
}
